



clear all
cap log close
set more off
set matsize 1600
set mem 100m

global ROOT ""
global data "$ROOT/Data"
global dofiles "$ROOT/DoFiles"
global tables "$ROOT/Tables"
global figures "$ROOT/Figures"

u "$risk_data\analysisfinal.dta", clear

*-------------------------------------------------------------------
*Deciding on the zones and villages
*-------------------------------------------------------------------
global ourcluster "zone_o"

*Village variable for the village fixed effects
*vill1 is for the village in the first wave
local village "vill1"

**Inverse hyperbolic sine transformation
gen iht_inc_crop = ln(inc_crop + sqrt(inc_crop + 1))

xtset num wave
gen diht_inc_crop = d.iht_inc_crop

cap drop linc_crop_p1 dlinc_crop_p1
gen linc_crop_p1 = ln(inc_crop*1000 + 1)

gen dlinc_crop_p1 = d.linc_crop_p1

/* USING ORIGINAL ZONES*/ 
/* First, generating interaction dummies between the shocks and women's group treatment variable */
qui {

 

*Shock variables
foreach y of varlist dcrop dinc_crop dlinc_crop_p1 dintensity diht_inc_crop  {
gen `y'_treat1 = `y'*wg_o

}

/* next creating interaction terms between the shock variable and an indicator for the control group*/
gen control = wg_o ==0
replace control = . if wg_o==.

foreach y of varlist dcrop dinc_crop dlinc_crop_p1 dintensity diht_inc_crop  {
gen `y'_control = `y'*control

}


}
*closing quietly above

*--------------------------------------------------------
*Building some variables that were not created before
*--------------------------------------------------------
gen d12_18=dfem12_18+dmale12_18
gen dmt18=dfemmt18+dmalemt18




/* Next for the regression. The regression we run is as follows:
dln(civt) = beta*dshock(ivt) + beta2*dshock(ivt)*wg_o + vt + uivt
It comes from the model of perfect risk sharing with CRRA utility. Test is similar to that used by Mace (1991) and Cochrane (1991)
 */

**************************************************
* Generating the dummy variables for each village
**************************************************
xi i.vill1 
global vill_dum "_Ivill1_*"

********************************************
 * Specification with village-time dummies
*********************************************
global regressors1 " ddays_oct dlt6 dsix_12 d12_18 dmt18"

gen dtot_food=dmfoodc
gen dltot_food=dlmfoodc


cd "$tables"
*---------------------------------------------------------------
*Consumption smoothing specification: total consumption and food
*----------------------------------------------------------------
cap erase "alternatives1_cons.log"
local file "alternatives1_cons.log"

cap erase "alternatives1_food.log"
local file2 "alternatives1_food.log"

global outregopts "nocons br dec(4)"

areg dltot_cons dintensity dintensity_treat1       $regressors1, cluster ($ourcluster) absorb(vill1)
gen sample1 = e(sample)
boottest dintensity
boottest dintensity_treat1
outreg2 using `file', $outregopts ctitle("dltot_cons, shock = dshare_new") title("Consumption Smoothing, WG interventions") keep(dshare_new dshare_new_treat1)

preserve
keep if sample1==1

// Income loss itself
areg dltot_cons dinc_crop dinc_crop_treat1       $regressors1, cluster ($ourcluster) absorb(vill1)
boottest dinc_crop
boottest dinc_crop_treat1
outreg2 using `file', $outregopts ctitle("dltot_cons, shock = dinc_crop") title("Consumption Smoothing, WG interventions") keep(dinc_crop dinc_crop_treat1)


//Changes in log income loss plus 1
areg dltot_cons dlinc_crop_p1 dlinc_crop_p1_treat1       $regressors1, cluster ($ourcluster) absorb(vill1)
boottest dlinc_crop_p1
boottest dlinc_crop_p1_treat1
outreg2 using `file', $outregopts ctitle("dltot_cons, shock = dlinc_crop_p1") title("Consumption Smoothing, WG interventions") keep(dlinc_crop_p1 dlinc_crop_p1_treat1)


//Inverse hyperbolic sine 
areg dltot_cons diht_inc_crop diht_inc_crop_treat1       $regressors1, cluster ($ourcluster) absorb(vill1)
boottest diht_inc_crop
boottest diht_inc_crop_treat1
outreg2 using `file', $outregopts ctitle("dltot_cons, shock = dinc_crop") title("Consumption Smoothing, WG interventions") keep(diht_inc_crop diht_inc_crop_treat1)

restore




//lfood

areg dltot_food dintensity dintensity_treat1       $regressors1, cluster ($ourcluster) absorb(vill1)
gen sample1 = e(sample)
boottest dintensity
boottest dintensity_treat1
outreg2 using `file', $outregopts ctitle("dltot_food, shock = dshare_new") title("Consumption Smoothing, WG interventions") keep(dshare_new dshare_new_treat1)

preserve
keep if sample1==1

// Income loss itself
areg dltot_food dinc_crop dinc_crop_treat1       $regressors1, cluster ($ourcluster) absorb(vill1)
boottest dinc_crop
boottest dinc_crop_treat1
outreg2 using `file', $outregopts ctitle("dltot_food, shock = dinc_crop") title("Consumption Smoothing, WG interventions") keep(dinc_crop dinc_crop_treat1)


//Changes in log income loss plus 1
areg dltot_food dlinc_crop_p1 dlinc_crop_p1_treat1       $regressors1, cluster ($ourcluster) absorb(vill1)
boottest dlinc_crop_p1
boottest dlinc_crop_p1_treat1
outreg2 using `file', $outregopts ctitle("dltot_food, shock = dlinc_crop_p1") title("Consumption Smoothing, WG interventions") keep(dlinc_crop_p1 dlinc_crop_p1_treat1)


//Inverse hyperbolic sine 
areg dltot_food diht_inc_crop diht_inc_crop_treat1       $regressors1, cluster ($ourcluster) absorb(vill1)
boottest diht_inc_crop
boottest diht_inc_crop_treat1
outreg2 using `file', $outregopts ctitle("dltot_food, shock = dinc_crop") title("Consumption Smoothing, WG interventions") keep(diht_inc_crop diht_inc_crop_treat1)

restore
